gpNamespace.GpMainScene=cc.Scene.extend({
	sceneName:gpNamespace.MainSceneName,

	ctor:function(){
		this._super();

		this.init();
	},

	init:function(){
		//大厅通用资源
//		cc.spriteFrameCache.addSpriteFrames(gpNamespace.tyRes.Ty_plist);
		//大厅MiddleLayer资源
//		cc.spriteFrameCache.addSpriteFrames(gpNamespace.plazaRes.Plaza_plist);
		//金色数字图片
		cc.spriteFrameCache.addSpriteFrames(gpNamespace.prepareRes.Prepare_plist);
		//各种数字图片
		cc.spriteFrameCache.addSpriteFrames(gpNamespace.jsnumRes.Jsnum_plist);
		//主界面排行的数字图片
		cc.spriteFrameCache.addSpriteFrames(gpNamespace.zjmnumRes.Zjmnum_plist);
//		cc.spriteFrameCache.addSpriteFrames(gpNamespace.noticeRes.Notice_plist);
		//提示框
		cc.spriteFrameCache.addSpriteFrames(gpNamespace.warningRes.Warning_plist);
		//新弹框
		cc.spriteFrameCache.addSpriteFrames(gpNamespace.pdkTanKuangRes.tankuang_plist);
		//金币、qq头像
		cc.spriteFrameCache.addSpriteFrames(gpNamespace.xinzengRes.xinzeng_plist);
		
		cc.spriteFrameCache.addSpriteFrames(gpNamespace.mainSenceFirstRes.MainSenceFirst_plist);

		ccs.armatureDataManager.addArmatureFileInfo(
				gpNamespace.loadingRes.Ty_zhaoziAnimation_png,
				gpNamespace.loadingRes.Ty_zhaoziAnimation_plist,
				gpNamespace.loadingRes.Ty_zhaoziAnimation_json);

		ccs.armatureDataManager.addArmatureFileInfo(
				gpNamespace.pochanRes.coins_png,
				gpNamespace.pochanRes.coins_plist,
				gpNamespace.pochanRes.coins_json);
	},

	onEnter:function(){
		this._super();
		cc.audioEngine.stopMusic(true);
//		gpNamespace.SoundManager.playMusic(gpNamespace.soundRes.BackgroundMusic, true);
//		gpNamespace.SoundManager.playMusic(gpNamespace.soundRes.BackgroundMusic, true);
		cc.audioEngine.playMusic(gpNamespace.soundRes.BackgroundMusic, true);
		cc.log("tyNamespace.IsPochan:" + tyNamespace.IsPochan + ",tyNamespace.IsLimit：" + tyNamespace.IsLimit + "tyNamespace.IsLimit:" + tyNamespace.IsLimit + ",tyNamespace.IsBuyOne" + tyNamespace.IsBuyOne);

		if (tyNamespace.IsPochan) {
			var modelCancelable = new tyNamespace.ModelLayerCancelable();
			var warnLayer = new tyNamespace.WarnLayer(tyNamespace.WarnType.Pochan, this.chargeCallback, this);
			warnLayer.setTouchArea(cc.size(524, 310), cc.p(378, 205));
			modelCancelable.addChild(warnLayer);
			this.addChild(modelCancelable, 100);

			tyNamespace.IsPochan = false;
		}

		if (tyNamespace.IsLimit) {
			var modelCancelable = new tyNamespace.ModelLayerCancelable();
			var jumpLayer = new tyNamespace.JumpLayer(tyNamespace.JumpType.Limit, function () {
			}, this, [this.index]);
			jumpLayer.setTouchArea(cc.size(524, 310), cc.p(378, 205));
			modelCancelable.addChild(jumpLayer);
			this.addChild(modelCancelable, 100);

			tyNamespace.IsLimit = false;
		}

		if (tyNamespace.IsLimitFen) {
			tyNamespace.addTextRemoveLayer("您的积分不足，无法继续！");

			tyNamespace.IsLimitFen = false;
		}

		if (tyNamespace.IsBuyOne) {
			var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
			var modelLayer = new tyNamespace.ModelLayer();
			modelLayer.setTouchArea(cc.size(647, 601), cc.p(267, 60));
			modelLayerCancelable.addChild(modelLayer);
			this.addChild(modelLayerCancelable, 100);

			var oneRMBLayer = new gpNamespace.CzdlbLayer();
			oneRMBLayer.attr({
				x: 0,
				y: cc.winSize.height
			});
			modelLayer.addChild(oneRMBLayer);

			tyNamespace.AnimationManager.nodeJumpShow(oneRMBLayer, -cc.winSize.height);

			tyNamespace.IsBuyOne = false;
		}

		var pdkBackgroundLayer = new gpNamespace.GpBackgroundLayer();
		this.addChild(pdkBackgroundLayer);

		var topLayer = new gpNamespace.TopLayer();
		this.addChild(topLayer);

		var middleLayer = new gpNamespace.gpMiddleLayer();
		this.addChild(middleLayer);

		var bottomLayer = new gpNamespace.BottomLayer();
		this.addChild(bottomLayer,1,"bottomLayer");
//		cc.director.getRunningScene().getChildByTag();
		//罩子
//		var runningScene = cc.director.getRunningScene();
//		var zhao = new tyNamespace.WaittingLayer(70,cc.p(600,360));
//		runningScene.addChild(zhao, 10,"juhua");
		
		cc.log("userInfo:"+userInfo);
		if(userInfo == null){
			tyNamespace.addWaitLayer();

			xinyou.netManager.init();
			//xinyou.netManager.initGameSocket("192.168.1.90", "8080/sfqq/websocket");
			xinyou.netManager.initGameSocket("192.168.1.90", "80/ceshi/websocket");
			//xinyou.netManager.initGameSocket("192.168.1.90", "80/MRSK/websocket");
//			xinyou.netManager.initGameSocket("115.159.39.184", "6060/sfqq/websocket");
			
//			xinyou.netManager.initGameSocket("192.168.1.152", "8080/sfqq/websocket");
//			xinyou.netManager.initGameSocket("115.159.28.251", "80/sfqq/websocket");
			gpNamespace.TyNetManager.getInstance();

			this.scheduleOnce(function () {
				xinyou.netManager.requestLogin("4453146455", "sdk", "http://q.qlogo.cn/g?b=qq&nk=16214659&s=100","1111");
			}, 2);
		} else {
			topLayer.setUserNameLabel(userInfo.nickName);
			topLayer.setUserGold(userInfo.gold);
			topLayer.setUserDiamond(userInfo.diamond);
			topLayer.setUserVoucher(userInfo.voucher);
			if (userInfo.isVip) {
				topLayer.showVip();
			}
			if(rankInfo != null) {
				middleLayer.setRankContainer(rankInfo);
			}
			bottomLayer.setEggTips();
			xinyou.netManager.getHistoryTalk();
		}
		
	},
	
	chargeCallback:function() {
		xinyou.netManager.inPhysicalExchange();//获取商城实物奖品的信息
		cc.log("狗to商城");
		var index = 4;

		var runningScene = cc.director.getRunningScene();
		var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
		var modelLayer = new tyNamespace.ModelLayer(70);
		modelLayer.setTouchArea(cc.size(1210, 570), cc.p(35, 35));
		modelLayerCancelable.addChild(modelLayer);
		runningScene.addChild(modelLayerCancelable, 200);
		var scLayer = new gpNamespace.ScLayer(index);
		scLayer.attr({
			//左上角坐标
			x: 0,
			y: cc.winSize.height
		});
		modelLayer.addChild(scLayer, 100);
		tyNamespace.AnimationManager.nodeJumpShow(scLayer, -cc.winSize.height);
	}
})